using MicroMsg.Manager;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class EmojiListPage : BasePage
	{
		private const string TAG = "EmojiListPage";
		private const int ListView = 0;
		private const int EmptyInfoView = 1;
		private EmojiSelectComplete mEmojiSelectComplete;
		private List<EmojiArt> currentEmojiArtList;
		private int currentLoadedArtIndex;
		internal Grid LayoutRoot;
		internal TextBlock PageTitle;
		internal ViewFlipper emojiFliper;
		internal StackPanel EmojiList;
		private bool _contentLoaded;
		public static void SelectCustomEmoji(BasePage originPage, EmojiSelectComplete emojiSelectComplete, EmojiArtGroup group)
		{
			originPage.GoToPage("/Source/UI/Chat/Emoji/EmojiListPage.xaml", new object[]
			{
				emojiSelectComplete,
				group
			}, false);
		}
		public EmojiListPage()
		{
			this.InitializeComponent();
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (object_0 != null)
			{
				if (Enumerable.Count<object>(object_0) == 2)
				{
					this.mEmojiSelectComplete = (object_0[0] as EmojiSelectComplete);
					EmojiArtGroup group = (EmojiArtGroup)object_0[1];
					this.InitEmojiList(group);
					return;
				}
			}
		}
		private void newItem_Loaded(object sender, RoutedEventArgs e)
		{
		}
		public void DoLoad()
		{
			if (this.currentEmojiArtList == null || this.currentEmojiArtList.get_Count() <= 0)
			{
				return;
			}
			if (this.currentLoadedArtIndex < 0 || this.currentLoadedArtIndex >= this.currentEmojiArtList.get_Count())
			{
				return;
			}
			EmojiArt emojiArt = this.currentEmojiArtList.get_Item(this.currentLoadedArtIndex);
			if (emojiArt == null)
			{
				return;
			}
			EmojiItem emojiItem = new EmojiItem();
			emojiItem.InitData(emojiArt, new RoutedEventHandler(this.OnItemDelete));
			emojiItem.add_Loaded(new RoutedEventHandler(this.newItem_Loaded));
			emojiItem.add_Click(new RoutedEventHandler(this.newItem_Click));
			this.EmojiList.get_Children().Add(emojiItem);
			this.currentLoadedArtIndex++;
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.DoLoad();
			});
		}
		public void RefreshEmptyInfo()
		{
			if (this.EmojiList.get_Children() != null && this.EmojiList.get_Children().get_Count() > 0)
			{
				this.emojiFliper.ShowView(0);
				return;
			}
			this.emojiFliper.ShowView(1);
		}
		public void OnItemDelete(object sender, RoutedEventArgs e)
		{
			EmojiItem emojiItem = sender as EmojiItem;
			if (emojiItem == null)
			{
				return;
			}
			EmojiArt mEmojiArt = emojiItem.mEmojiArt;
			if (mEmojiArt == null)
			{
				return;
			}
			using (IEnumerator<UIElement> enumerator = this.EmojiList.get_Children().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					UIElement current = enumerator.get_Current();
					EmojiItem emojiItem2 = current as EmojiItem;
					if (emojiItem2 != null && emojiItem2 == emojiItem)
					{
						this.EmojiList.get_Children().Remove(emojiItem2);
						StorageMgr.emojiArt.method_4(mEmojiArt);
						break;
					}
				}
			}
		}
		public void InitEmojiList(EmojiArtGroup group)
		{
			if (group == null)
			{
				return;
			}
			if (R.isChineseTW())
			{
				this.PageTitle.set_Text(group.strPackName_zh_tw);
			}
			else
			{
				if (R.isChineseCN())
				{
					this.PageTitle.set_Text(group.strPackName_zh_cn);
				}
				else
				{
					this.PageTitle.set_Text(group.strPackName_en_us);
				}
			}
			List<EmojiArt> list = EmojiManager.getList(group.nPackID, group.nPackID == 1);
			if (list != null && list.get_Count() > 0)
			{
				this.currentEmojiArtList = list;
				this.currentLoadedArtIndex = 0;
				this.DoLoad();
				this.RefreshEmptyInfo();
				return;
			}
			this.RefreshEmptyInfo();
		}
		private void newItem_Click(object sender, RoutedEventArgs e)
		{
			EmojiItem emojiItem = sender as EmojiItem;
			if (emojiItem == null)
			{
				return;
			}
			if (this.mEmojiSelectComplete != null)
			{
				this.mEmojiSelectComplete(emojiItem.Text);
			}
			base.GoBack();
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Chat/Emoji/EmojiListPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.PageTitle = (TextBlock)base.FindName("PageTitle");
			this.emojiFliper = (ViewFlipper)base.FindName("emojiFliper");
			this.EmojiList = (StackPanel)base.FindName("EmojiList");
		}
	}
}
